package com.bclz.task.flow;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import com.bclz.entity.Summarizing;

/** 
* @ClassName: FlowStatisticReduce  
* @Description: 统计每个手机号的总上行流量和总下行流量reduce操作
* @author xuchang  
* @date 2018年9月28日
 */
public class FlowStatisticReduce extends Reducer<Text, Summarizing, Text, Summarizing> {
		
	
	
	@Override
	protected void reduce(Text key, Iterable<Summarizing> value,Context result) throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		
		Iterator<Summarizing> iterator = value.iterator();
		long upFlow=0;
		long downFlow=0;
		while(iterator.hasNext()) {
			Summarizing next = iterator.next();
			downFlow+=next.getDownFlow();
			upFlow+=next.getUpFlow();
		}
		
		result.write(key, new Summarizing(upFlow,downFlow));
	}
}
